package cn.aitrox.ry.common.exception;

import cn.aitrox.ry.enumtype.RespCodeEnum;
import com.google.common.base.Strings;

public class CustomBizException extends RuntimeException {

    private static final long serialVersionUID = 1L;
    private int code;
    private String subcode;

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getSubcode() {
        return this.subcode;
    }

    public void setSubcode(String subcode) {
        this.subcode = subcode;
    }

    public CustomBizException(int code, String message) {
        super(message);
        this.code = code;
    }

    public CustomBizException(int code, String message, String subcode) {
        super(message);
        this.code = code;
        this.subcode = subcode;
    }

    public CustomBizException(String message) {
        super(message);
        this.code = RespCodeEnum.ERROR.getCode();
    }

    public CustomBizException(RespCodeEnum apiCodeEnum) {
        super(apiCodeEnum.getMessage());
        this.code = apiCodeEnum.getCode();
    }

    public CustomBizException(RespCodeEnum apiCodeEnum, String message) {
        super(message);
        this.code = apiCodeEnum.getCode();
    }

    public CustomBizException(RespCodeEnum apiCodeEnum, String message, String subcode) {
        super(Strings.isNullOrEmpty(message) ? apiCodeEnum.getMessage() : message);
        this.code = apiCodeEnum.getCode();
        this.subcode = subcode;
    }
}
